package com.xnx.bincker.leader.advice;

import com.xnx.bincker.leader.exception.SystemException;
import com.xnx.bincker.leader.exception.data.ValidationException;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletResponse;

/**
 * 数据验证失败处理类
 */
@RestControllerAdvice
public class ValidationExceptionHandler {
    @ExceptionHandler
    public SystemException handle(HttpServletResponse response, BindException exception){
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return new ValidationException(exception.getFieldErrors());
    }
}
